{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8cee4602",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "csv_path = r\"E:\\oo\\csv\" #这一章要重新出类型csv，新的csv的路径\n",
    "\n",
    "name = \"琐琐荒漠\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "66963829",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "import matplotlib.path as mpltPath\n",
    "import os\n",
    "\n",
    "\"\"\"\n",
    "这是各个区的重心-名称字典，通过重心可以得到这个区的名称\n",
    "\"\"\"\n",
    "sign = {(0.0, 23.572): '1a', (0.0, 70.716): '1b', (0.0, 117.86): '1c', (0.0, 165.004): '1d', (0.0, 212.148): '1e', (0.0, 259.292): '1f', (0.0, 306.436): '1g', (0.0, 353.58): '1h', (0.0, 400.724): '1i', (0.0, 447.868): '1j', (0.0, 495.012): '1k', (0.0, 542.156): '1l', (0.0, 589.3): '1m', (0.0, 636.444): '1n', (0.0, 683.588): '1o', (0.0, 730.732): '1p', (0.0, 777.876): '1q', (0.0, 825.02): '1r', (4.0, -0.0): '2a', (4.0, 47.144): '2b', (4.0, 94.288): '2c', (4.0, 141.432): '2d', (4.0, 188.576): '2e', (4.0, 235.72): '2f', (4.0, 282.864): '2g', (4.0, 330.008): '2h', (4.0, 377.152): '2i', (4.0, 424.296): '2j', (4.0, 471.44): '2k', (4.0, 518.584): '2l', (4.0, 565.728): '2m', (4.0, 612.872): '2n', (4.0, 660.016): '2o', (4.0, 707.16): '2p', (4.0, 754.304): '2q', (4.0, 801.448): '2r', (8.0, -23.572): '3a', (8.0, 23.572): '3b', (8.0, 70.716): '3c', (8.0, 117.86): '3d', (8.0, 165.004): '3e', (8.0, 212.148): '3f', (8.0, 259.292): '3g', (8.0, 306.436): '3h', (8.0, 353.58): '3i', (8.0, 400.724): '3j', (8.0, 447.868): '3k', (8.0, 495.012): '3l', (8.0, 542.156): '3m', (8.0, 589.3): '3n', (8.0, 636.444): '3o', (8.0, 683.588): '3p', (8.0, 730.732): '3q', (8.0, 777.876): '3r', (8.0, 825.02): '3s', (12.0, -47.144): '4a', (12.0, 0.0): '4b', (12.0, 47.144): '4c', (12.0, 94.288): '4d', (12.0, 141.432): '4e', (12.0, 188.576): '4f', (12.0, 235.72): '4g', (12.0, 282.864): '4h', (12.0, 330.008): '4i', (12.0, 377.152): '4j', (12.0, 424.296): '4k', (12.0, 471.44): '4l', (12.0, 518.584): '4m', (12.0, 565.728): '4n', (12.0, 612.872): '4o', (12.0, 660.016): '4p', (12.0, 707.16): '4q', (12.0, 754.304): '4r', (12.0, 801.448): '4s', (16.0, -70.716): '5a', (16.0, -23.572): '5b', (16.0, 23.572): '5c', (16.0, 70.716): '5d', (16.0, 117.86): '5e', (16.0, 165.004): '5f', (16.0, 212.148): '5g', (16.0, 259.292): '5h', (16.0, 306.436): '5i', (16.0, 353.58): '5j', (16.0, 400.724): '5k', (16.0, 447.868): '5l', (16.0, 495.012): '5m', (16.0, 542.156): '5n', (16.0, 589.3): '5o', (16.0, 636.444): '5p', (16.0, 683.588): '5q', (16.0, 730.732): '5r', (16.0, 777.876): '5s', (16.0, 825.02): '5t', (20.0, -94.288): '6a', (20.0, -47.144): '6b', (20.0, -0.0): '6c', (20.0, 47.144): '6d', (20.0, 94.288): '6e', (20.0, 141.432): '6f', (20.0, 188.576): '6g', (20.0, 235.72): '6h', (20.0, 282.864): '6i', (20.0, 330.008): '6j', (20.0, 377.152): '6k', (20.0, 424.296): '6l', (20.0, 471.44): '6m', (20.0, 518.584): '6n', (20.0, 565.728): '6o', (20.0, 612.872): '6p', (20.0, 660.016): '6q', (20.0, 707.16): '6r', (20.0, 754.304): '6s', (20.0, 801.448): '6t', (24.0, -117.86): '7a', (24.0, -70.716): '7b', (24.0, -23.572): '7c', (24.0, 23.572): '7d', (24.0, 70.716): '7e', (24.0, 117.86): '7f', (24.0, 165.004): '7g', (24.0, 212.148): '7h', (24.0, 259.292): '7i', (24.0, 306.436): '7j', (24.0, 353.58): '7k', (24.0, 400.724): '7l', (24.0, 447.868): '7m', (24.0, 495.012): '7n', (24.0, 542.156): '7o', (24.0, 589.3): '7p', (24.0, 636.444): '7q', (24.0, 683.588): '7r', (24.0, 730.732): '7s', (24.0, 777.876): '7t', (24.0, 825.02): '7u', (6.889, 90.359): '3c-3', (5.778, 70.716): '3c-2', (6.889, 43.215): '3b-3', (6.889, 137.503): '3d-3', (6.889, 184.647): '3e-3', (5.778, 165.004): '3e-2', (6.889, 145.361): '3e-1', (6.889, 98.217): '3d-1', (5.778, 117.86): '3d-2', (6.889, 231.791): '3f-3', (6.889, 192.505): '3f-1', (6.889, 278.935): '3g-3', (5.778, 259.292): '3g-2', (6.889, 239.649): '3g-1', (5.778, 306.436): '3h-2', (5.778, 353.58): '3i-2', (6.889, 286.793): '3h-1', (6.889, 326.079): '3h-3', (5.778, 400.724): '3j-2', (6.889, 333.937): '3i-1', (6.889, 373.223): '3i-3', (5.778, 447.868): '3k-2', (6.889, 381.081): '3j-1', (6.889, 420.367): '3j-3', (6.889, 514.655): '3l-3', (5.778, 495.012): '3l-2', (6.889, 428.225): '3k-1', (6.889, 467.511): '3k-3', (6.889, 561.799): '3m-3', (5.778, 542.156): '3m-2', (6.889, 522.513): '3m-1', (6.889, 608.943): '3n-3', (5.778, 589.3): '3n-2', (6.889, 656.087): '3o-3', (5.778, 636.444): '3o-2', (6.889, 703.231): '3p-3', (5.778, 683.588): '3p-2', (6.889, 750.375): '3q-3', (5.778, 730.732): '3q-2', (6.889, 797.519): '3r-3', (5.778, 777.876): '3r-2', (6.889, 758.233): '3r-1', (6.889, 805.377): '3s-1', (10.889, 66.787): '4c-3', (10.889, 161.075): '4e-3', (10.889, 74.645): '4d-1', (10.889, 113.931): '4d-3', (10.889, 208.219): '4f-3', (10.889, 168.933): '4f-1', (10.889, 121.789): '4e-1', (10.889, 255.363): '4g-3', (10.889, 216.077): '4g-1', (10.889, 302.507): '4h-3', (10.889, 263.221): '4h-1', (10.889, 310.365): '4i-1', (10.889, 349.651): '4i-3', (10.889, 357.509): '4j-1', (10.889, 396.795): '4j-3', (10.889, 404.653): '4k-1', (10.889, 443.939): '4k-3', (10.889, 538.227): '4m-3', (10.889, 498.941): '4m-1', (10.889, 585.371): '4n-3', (10.889, 632.515): '4o-3', (10.889, 679.659): '4p-3', (10.889, 726.803): '4q-3', (10.889, 773.947): '4r-3', (10.889, 734.661): '4r-1', (10.889, 781.805): '4s-1', (14.889, -43.215): '5b-1', (14.889, 90.359): '5d-3', (14.889, 43.215): '5c-3', (14.889, 137.503): '5e-3', (14.889, 184.647): '5f-3', (14.889, 145.361): '5f-1', (14.889, 98.217): '5e-1', (14.889, 231.791): '5g-3', (14.889, 192.505): '5g-1', (14.889, 278.935): '5h-3', (14.889, 239.649): '5h-1', (14.889, 286.793): '5i-1', (14.889, 326.079): '5i-3', (14.889, 333.937): '5j-1', (14.889, 373.223): '5j-3', (14.889, 381.081): '5k-1', (14.889, 420.367): '5k-3', (14.889, 514.655): '5m-3', (14.889, 428.225): '5l-1', (14.889, 467.511): '5l-3', (14.889, 561.799): '5n-3', (14.889, 522.513): '5n-1', (14.889, 608.943): '5o-3', (14.889, 656.087): '5p-3', (14.889, 703.231): '5q-3', (14.889, 750.375): '5r-3', (14.889, 797.519): '5s-3', (14.889, 758.233): '5s-1', (14.889, 805.377): '5t-1', (18.889, -66.787): '6b-1', (18.889, 66.787): '6d-3', (18.889, 161.075): '6f-3', (17.778, 141.432): '6f-2', (18.889, 74.645): '6e-1', (17.778, 94.288): '6e-2', (18.889, 113.931): '6e-3', (18.889, 208.219): '6g-3', (18.889, 168.933): '6g-1', (18.889, 121.789): '6f-1', (18.889, 255.363): '6h-3', (18.889, 216.077): '6h-1', (18.889, 302.507): '6i-3', (17.778, 282.864): '6i-2', (18.889, 263.221): '6i-1', (17.778, 330.008): '6j-2', (17.778, 377.152): '6k-2', (18.889, 310.365): '6j-1', (18.889, 349.651): '6j-3', (17.778, 424.296): '6l-2', (18.889, 357.509): '6k-1', (18.889, 396.795): '6k-3', (17.778, 471.44): '6m-2', (18.889, 404.653): '6l-1', (18.889, 443.939): '6l-3', (18.889, 538.227): '6n-3', (17.778, 518.584): '6n-2', (18.889, 498.941): '6n-1', (18.889, 585.371): '6o-3', (17.778, 565.728): '6o-2', (18.889, 632.515): '6p-3', (17.778, 612.872): '6p-2', (18.889, 679.659): '6q-3', (17.778, 660.016): '6q-2', (18.889, 726.803): '6r-3', (17.778, 707.16): '6r-2', (18.889, 773.947): '6s-3', (17.778, 754.304): '6s-2', (18.889, 734.661): '6s-1', (17.778, 801.448): '6t-2', (18.889, 781.805): '6t-1', (22.889, -43.215): '7c-1', (22.889, -90.359): '7b-1', (21.778, -70.716): '7b-2', (22.889, 90.359): '7e-3', (21.778, 70.716): '7e-2', (22.889, 43.215): '7d-3', (22.889, 137.503): '7f-3', (22.889, 184.647): '7g-3', (21.778, 165.004): '7g-2', (22.889, 145.361): '7g-1', (22.889, 98.217): '7f-1', (21.778, 117.86): '7f-2', (22.889, 231.791): '7h-3', (22.889, 192.505): '7h-1', (22.889, 278.935): '7i-3', (21.778, 259.292): '7i-2', (22.889, 239.649): '7i-1', (21.778, 306.436): '7j-2', (21.778, 353.58): '7k-2', (22.889, 286.793): '7j-1', (22.889, 326.079): '7j-3', (21.778, 400.724): '7l-2', (22.889, 333.937): '7k-1', (22.889, 373.223): '7k-3', (21.778, 447.868): '7m-2', (22.889, 381.081): '7l-1', (22.889, 420.367): '7l-3', (22.889, 514.655): '7n-3', (21.778, 495.012): '7n-2', (22.889, 428.225): '7m-1', (22.889, 467.511): '7m-3', (22.889, 561.799): '7o-3', (21.778, 542.156): '7o-2', (22.889, 522.513): '7o-1', (22.889, 608.943): '7p-3', (21.778, 589.3): '7p-2', (22.889, 656.087): '7q-3', (21.778, 636.444): '7q-2', (22.889, 703.231): '7r-3', (21.778, 683.588): '7r-2', (22.889, 750.375): '7s-3', (21.778, 730.732): '7s-2', (22.889, 797.519): '7t-3', (21.778, 777.876): '7t-2', (22.889, 758.233): '7t-1', (22.889, 805.377): '7u-1', (2.889, 66.787): '2b-3', (1.778, 47.144): '2b-2', (2.889, 27.501): '2b-1', (2.889, 19.643): '2a-2', (2.889, 113.931): '2c-3', (1.778, 94.288): '2c-2', (2.889, 74.645): '2c-1', (2.889, 161.075): '2d-3', (1.778, 141.432): '2d-2', (2.889, 121.789): '2d-1', (2.889, 208.219): '2e-3', (1.778, 188.576): '2e-2', (2.889, 168.933): '2e-1', (2.889, 255.363): '2f-3', (1.778, 235.72): '2f-2', (2.889, 216.077): '2f-1', (2.889, 302.507): '2g-3', (1.778, 282.864): '2g-2', (2.889, 263.221): '2g-1', (2.889, 349.651): '2h-3', (1.778, 330.008): '2h-2', (2.889, 310.365): '2h-1', (2.889, 396.795): '2i-3', (1.778, 377.152): '2i-2', (2.889, 357.509): '2i-1', (2.889, 443.939): '2j-3', (1.778, 424.296): '2j-2', (2.889, 404.653): '2j-1', (2.889, 491.083): '2k-3', (1.778, 471.44): '2k-2', (2.889, 451.797): '2k-1', (2.889, 538.227): '2l-3', (1.778, 518.584): '2l-2', (2.889, 498.941): '2l-1', (2.889, 585.371): '2m-3', (1.778, 565.728): '2m-2', (2.889, 546.085): '2m-1', (2.889, 632.515): '2n-3', (1.778, 612.872): '2n-2', (2.889, 593.229): '2n-1', (2.889, 679.659): '2o-3', (1.778, 660.016): '2o-2', (2.889, 640.373): '2o-1', (2.889, 726.803): '2p-3', (1.778, 707.16): '2p-2', (2.889, 687.517): '2p-1', (2.889, 773.947): '2q-3', (1.778, 754.304): '2q-2', (2.889, 734.661): '2q-1', (1.778, 801.448): '2r-2', (2.889, 781.805): '2r-1', (5.778, 23.572): '3b-2', (5.778, -23.572): '3a-1', (6.889, 51.073): '3c-1', (5.778, 212.148): '3f-2', (6.889, 475.369): '3l-1', (6.889, 569.657): '3n-1', (6.889, 616.801): '3o-1', (6.889, 663.945): '3p-1', (6.889, 711.089): '3q-1', (10.889, 19.643): '4b-3', (10.889, -19.643): '4b-1', (9.778, -47.144): '4a-1', (10.889, -27.501): '4a-2', (9.778, 47.144): '4c-2', (10.889, 27.501): '4c-1', (9.778, 94.288): '4d-2', (9.778, 141.432): '4e-2', (9.778, 188.576): '4f-2', (9.778, 235.72): '4g-2', (9.778, 282.864): '4h-2', (9.778, 330.008): '4i-2', (9.778, 377.152): '4j-2', (9.778, 424.296): '4k-2', (10.889, 491.083): '4l-3', (9.778, 471.44): '4l-2', (10.889, 451.797): '4l-1', (9.778, 518.584): '4m-2', (9.778, 565.728): '4n-2', (10.889, 546.085): '4n-1', (9.778, 612.872): '4o-2', (10.889, 593.229): '4o-1', (9.778, 660.016): '4p-2', (10.889, 640.373): '4p-1', (9.778, 707.16): '4q-2', (10.889, 687.517): '4q-1', (9.778, 754.304): '4r-2', (9.778, 801.448): '4s-2', (13.778, -23.572): '5b-2', (13.778, -70.716): '5a-1', (14.889, -51.073): '5a-2', (13.778, 23.572): '5c-2', (13.778, 70.716): '5d-2', (14.889, 51.073): '5d-1', (13.778, 117.86): '5e-2', (13.778, 165.004): '5f-2', (13.778, 212.148): '5g-2', (13.778, 259.292): '5h-2', (13.778, 306.436): '5i-2', (13.778, 353.58): '5j-2', (13.778, 400.724): '5k-2', (13.778, 447.868): '5l-2', (13.778, 495.012): '5m-2', (14.889, 475.369): '5m-1', (13.778, 542.156): '5n-2', (13.778, 589.3): '5o-2', (14.889, 569.657): '5o-1', (13.778, 636.444): '5p-2', (14.889, 616.801): '5p-1', (13.778, 683.588): '5q-2', (14.889, 663.945): '5q-1', (13.778, 730.732): '5r-2', (14.889, 711.089): '5r-1', (13.778, 777.876): '5s-2', (18.889, -27.501): '6b-3', (17.778, -47.144): '6b-2', (17.778, -94.288): '6a-1', (18.889, -74.645): '6a-2', (18.889, 19.643): '6c-3', (18.889, -19.643): '6c-1', (17.778, 47.144): '6d-2', (18.889, 27.501): '6d-1', (17.778, 188.576): '6g-2', (17.778, 235.72): '6h-2', (18.889, 491.083): '6m-3', (18.889, 451.797): '6m-1', (18.889, 546.085): '6o-1', (18.889, 593.229): '6p-1', (18.889, 640.373): '6q-1', (18.889, 687.517): '6r-1', (22.889, -51.073): '7b-3', (21.778, -117.86): '7a-1', (22.889, -98.217): '7a-2', (21.778, -23.572): '7c-2', (21.778, 23.572): '7d-2', (22.889, 51.073): '7e-1', (21.778, 212.148): '7h-2', (22.889, 475.369): '7n-1', (22.889, 569.657): '7p-1', (22.889, 616.801): '7q-1', (22.889, 663.945): '7r-1', (22.889, 711.089): '7s-1', (1.111, 90.359): '1b-1', (2.222, 70.716): '1b-2', (1.111, 51.073): '1b-3', (1.111, 137.503): '1c-1', (2.222, 117.86): '1c-2', (1.111, 98.217): '1c-3', (1.111, 184.647): '1d-1', (2.222, 165.004): '1d-2', (1.111, 145.361): '1d-3', (1.111, 231.791): '1e-1', (2.222, 212.148): '1e-2', (1.111, 192.505): '1e-3', (1.111, 278.935): '1f-1', (2.222, 259.292): '1f-2', (1.111, 239.649): '1f-3', (1.111, 326.079): '1g-1', (2.222, 306.436): '1g-2', (1.111, 286.793): '1g-3', (1.111, 373.223): '1h-1', (2.222, 353.58): '1h-2', (1.111, 333.937): '1h-3', (1.111, 420.367): '1i-1', (2.222, 400.724): '1i-2', (1.111, 381.081): '1i-3', (1.111, 467.511): '1j-1', (2.222, 447.868): '1j-2', (1.111, 428.225): '1j-3', (1.111, 514.655): '1k-1', (2.222, 495.012): '1k-2', (1.111, 475.369): '1k-3', (1.111, 561.799): '1l-1', (2.222, 542.156): '1l-2', (1.111, 522.513): '1l-3', (1.111, 608.943): '1m-1', (2.222, 589.3): '1m-2', (1.111, 569.657): '1m-3', (1.111, 656.087): '1n-1', (2.222, 636.444): '1n-2', (1.111, 616.801): '1n-3', (1.111, 703.231): '1o-1', (2.222, 683.588): '1o-2', (1.111, 663.945): '1o-3', (1.111, 750.375): '1p-1', (2.222, 730.732): '1p-2', (1.111, 711.089): '1p-3', (1.111, 797.519): '1q-1', (2.222, 777.876): '1q-2', (1.111, 758.233): '1q-3', (1.111, 805.377): '1r-1', (5.111, 66.787): '2b-4', (6.222, 47.144): '2b-5', (5.111, 27.501): '2b-6', (1.778, 0.0): '2a-1', (5.111, 113.931): '2c-4', (6.222, 94.288): '2c-5', (5.111, 74.645): '2c-6', (5.111, 161.075): '2d-4', (6.222, 141.432): '2d-5', (5.111, 121.789): '2d-6', (5.111, 208.219): '2e-4', (6.222, 188.576): '2e-5', (5.111, 168.933): '2e-6', (5.111, 255.363): '2f-4', (6.222, 235.72): '2f-5', (5.111, 216.077): '2f-6', (5.111, 302.507): '2g-4', (6.222, 282.864): '2g-5', (5.111, 263.221): '2g-6', (5.111, 349.651): '2h-4', (6.222, 330.008): '2h-5', (5.111, 310.365): '2h-6', (5.111, 396.795): '2i-4', (6.222, 377.152): '2i-5', (5.111, 357.509): '2i-6', (5.111, 443.939): '2j-4', (6.222, 424.296): '2j-5', (5.111, 404.653): '2j-6', (5.111, 491.083): '2k-4', (6.222, 471.44): '2k-5', (5.111, 451.797): '2k-6', (5.111, 538.227): '2l-4', (6.222, 518.584): '2l-5', (5.111, 498.941): '2l-6', (5.111, 585.371): '2m-4', (6.222, 565.728): '2m-5', (5.111, 546.085): '2m-6', (5.111, 632.515): '2n-4', (6.222, 612.872): '2n-5', (5.111, 593.229): '2n-6', (5.111, 679.659): '2o-4', (6.222, 660.016): '2o-5', (5.111, 640.373): '2o-6', (5.111, 726.803): '2p-4', (6.222, 707.16): '2p-5', (5.111, 687.517): '2p-6', (5.111, 773.947): '2q-4', (6.222, 754.304): '2q-5', (5.111, 734.661): '2q-6', (6.222, 801.448): '2r-3', (5.111, 781.805): '2r-4', (9.111, 43.215): '3b-4', (10.222, 23.572): '3b-5', (9.111, 3.929): '3b-6', (6.889, -3.929): '3a-2', (9.111, 90.359): '3c-4', (10.222, 70.716): '3c-5', (9.111, 51.073): '3c-6', (6.889, 3.929): '3b-1', (9.111, 137.503): '3d-4', (10.222, 117.86): '3d-5', (9.111, 98.217): '3d-6', (9.111, 184.647): '3e-4', (10.222, 165.004): '3e-5', (9.111, 145.361): '3e-6', (9.111, 231.791): '3f-4', (10.222, 212.148): '3f-5', (9.111, 192.505): '3f-6', (9.111, 278.935): '3g-4', (10.222, 259.292): '3g-5', (9.111, 239.649): '3g-6', (9.111, 326.079): '3h-4', (10.222, 306.436): '3h-5', (9.111, 286.793): '3h-6', (9.111, 373.223): '3i-4', (10.222, 353.58): '3i-5', (9.111, 333.937): '3i-6', (9.111, 420.367): '3j-4', (10.222, 400.724): '3j-5', (9.111, 381.081): '3j-6', (9.111, 467.511): '3k-4', (10.222, 447.868): '3k-5', (9.111, 428.225): '3k-6', (9.111, 514.655): '3l-4', (10.222, 495.012): '3l-5', (9.111, 475.369): '3l-6', (9.111, 561.799): '3m-4', (10.222, 542.156): '3m-5', (9.111, 522.513): '3m-6', (9.111, 608.943): '3n-4', (10.222, 589.3): '3n-5', (9.111, 569.657): '3n-6', (9.111, 656.087): '3o-4', (10.222, 636.444): '3o-5', (9.111, 616.801): '3o-6', (9.111, 703.231): '3p-4', (10.222, 683.588): '3p-5', (9.111, 663.945): '3p-6', (9.111, 750.375): '3q-4', (10.222, 730.732): '3q-5', (9.111, 711.089): '3q-6', (9.111, 797.519): '3r-4', (10.222, 777.876): '3r-5', (9.111, 758.233): '3r-6', (9.111, 805.377): '3s-2', (13.111, 19.643): '4b-4', (14.222, 0.0): '4b-5', (13.111, -19.643): '4b-6', (13.111, 66.787): '4c-4', (14.222, 47.144): '4c-5', (13.111, 27.501): '4c-6', (9.778, 0.0): '4b-2', (13.111, 113.931): '4d-4', (14.222, 94.288): '4d-5', (13.111, 74.645): '4d-6', (13.111, 161.075): '4e-4', (14.222, 141.432): '4e-5', (13.111, 121.789): '4e-6', (13.111, 208.219): '4f-4', (14.222, 188.576): '4f-5', (13.111, 168.933): '4f-6', (13.111, 255.363): '4g-4', (14.222, 235.72): '4g-5', (13.111, 216.077): '4g-6', (13.111, 302.507): '4h-4', (14.222, 282.864): '4h-5', (13.111, 263.221): '4h-6', (13.111, 349.651): '4i-4', (14.222, 330.008): '4i-5', (13.111, 310.365): '4i-6', (13.111, 396.795): '4j-4', (14.222, 377.152): '4j-5', (13.111, 357.509): '4j-6', (13.111, 443.939): '4k-4', (14.222, 424.296): '4k-5', (13.111, 404.653): '4k-6', (13.111, 491.083): '4l-4', (14.222, 471.44): '4l-5', (13.111, 451.797): '4l-6', (13.111, 538.227): '4m-4', (14.222, 518.584): '4m-5', (13.111, 498.941): '4m-6', (13.111, 585.371): '4n-4', (14.222, 565.728): '4n-5', (13.111, 546.085): '4n-6', (13.111, 632.515): '4o-4', (14.222, 612.872): '4o-5', (13.111, 593.229): '4o-6', (13.111, 679.659): '4p-4', (14.222, 660.016): '4p-5', (13.111, 640.373): '4p-6', (13.111, 726.803): '4q-4', (14.222, 707.16): '4q-5', (13.111, 687.517): '4q-6', (13.111, 773.947): '4r-4', (14.222, 754.304): '4r-5', (13.111, 734.661): '4r-6', (14.222, 801.448): '4s-3', (13.111, 781.805): '4s-4', (17.111, -3.929): '5b-4', (18.222, -23.572): '5b-5', (17.111, -43.215): '5b-6', (17.111, 43.215): '5c-4', (18.222, 23.572): '5c-5', (17.111, 3.929): '5c-6', (14.889, -3.929): '5b-3', (17.111, 90.359): '5d-4', (18.222, 70.716): '5d-5', (17.111, 51.073): '5d-6', (14.889, 3.929): '5c-1', (17.111, 137.503): '5e-4', (18.222, 117.86): '5e-5', (17.111, 98.217): '5e-6', (17.111, 184.647): '5f-4', (18.222, 165.004): '5f-5', (17.111, 145.361): '5f-6', (17.111, 231.791): '5g-4', (18.222, 212.148): '5g-5', (17.111, 192.505): '5g-6', (17.111, 278.935): '5h-4', (18.222, 259.292): '5h-5', (17.111, 239.649): '5h-6', (17.111, 326.079): '5i-4', (18.222, 306.436): '5i-5', (17.111, 286.793): '5i-6', (17.111, 373.223): '5j-4', (18.222, 353.58): '5j-5', (17.111, 333.937): '5j-6', (17.111, 420.367): '5k-4', (18.222, 400.724): '5k-5', (17.111, 381.081): '5k-6', (17.111, 467.511): '5l-4', (18.222, 447.868): '5l-5', (17.111, 428.225): '5l-6', (17.111, 514.655): '5m-4', (18.222, 495.012): '5m-5', (17.111, 475.369): '5m-6', (17.111, 561.799): '5n-4', (18.222, 542.156): '5n-5', (17.111, 522.513): '5n-6', (17.111, 608.943): '5o-4', (18.222, 589.3): '5o-5', (17.111, 569.657): '5o-6', (17.111, 656.087): '5p-4', (18.222, 636.444): '5p-5', (17.111, 616.801): '5p-6', (17.111, 703.231): '5q-4', (18.222, 683.588): '5q-5', (17.111, 663.945): '5q-6', (17.111, 750.375): '5r-4', (18.222, 730.732): '5r-5', (17.111, 711.089): '5r-6', (17.111, 797.519): '5s-4', (18.222, 777.876): '5s-5', (17.111, 758.233): '5s-6', (17.111, 805.377): '5t-2', (21.111, -27.501): '6b-4', (22.222, -47.144): '6b-5', (21.111, -66.787): '6b-6', (21.111, 19.643): '6c-4', (22.222, 0.0): '6c-5', (21.111, -19.643): '6c-6', (21.111, 66.787): '6d-4', (22.222, 47.144): '6d-5', (21.111, 27.501): '6d-6', (17.778, 0.0): '6c-2', (21.111, 113.931): '6e-4', (22.222, 94.288): '6e-5', (21.111, 74.645): '6e-6', (21.111, 161.075): '6f-4', (22.222, 141.432): '6f-5', (21.111, 121.789): '6f-6', (21.111, 208.219): '6g-4', (22.222, 188.576): '6g-5', (21.111, 168.933): '6g-6', (21.111, 255.363): '6h-4', (22.222, 235.72): '6h-5', (21.111, 216.077): '6h-6', (21.111, 302.507): '6i-4', (22.222, 282.864): '6i-5', (21.111, 263.221): '6i-6', (21.111, 349.651): '6j-4', (22.222, 330.008): '6j-5', (21.111, 310.365): '6j-6', (21.111, 396.795): '6k-4', (22.222, 377.152): '6k-5', (21.111, 357.509): '6k-6', (21.111, 443.939): '6l-4', (22.222, 424.296): '6l-5', (21.111, 404.653): '6l-6', (21.111, 491.083): '6m-4', (22.222, 471.44): '6m-5', (21.111, 451.797): '6m-6', (21.111, 538.227): '6n-4', (22.222, 518.584): '6n-5', (21.111, 498.941): '6n-6', (21.111, 585.371): '6o-4', (22.222, 565.728): '6o-5', (21.111, 546.085): '6o-6', (21.111, 632.515): '6p-4', (22.222, 612.872): '6p-5', (21.111, 593.229): '6p-6', (21.111, 679.659): '6q-4', (22.222, 660.016): '6q-5', (21.111, 640.373): '6q-6', (21.111, 726.803): '6r-4', (22.222, 707.16): '6r-5', (21.111, 687.517): '6r-6', (21.111, 773.947): '6s-4', (22.222, 754.304): '6s-5', (21.111, 734.661): '6s-6', (22.222, 801.448): '6t-3', (21.111, 781.805): '6t-4', (25.111, -51.073): '7b-4', (26.222, -70.716): '7b-5', (25.111, -90.359): '7b-6', (25.111, -3.929): '7c-4', (26.222, -23.572): '7c-5', (25.111, -43.215): '7c-6', (25.111, 43.215): '7d-4', (26.222, 23.572): '7d-5', (25.111, 3.929): '7d-6', (22.889, -3.929): '7c-3', (25.111, 90.359): '7e-4', (26.222, 70.716): '7e-5', (25.111, 51.073): '7e-6', (22.889, 3.929): '7d-1', (25.111, 137.503): '7f-4', (26.222, 117.86): '7f-5', (25.111, 98.217): '7f-6', (25.111, 184.647): '7g-4', (26.222, 165.004): '7g-5', (25.111, 145.361): '7g-6', (25.111, 231.791): '7h-4', (26.222, 212.148): '7h-5', (25.111, 192.505): '7h-6', (25.111, 278.935): '7i-4', (26.222, 259.292): '7i-5', (25.111, 239.649): '7i-6', (25.111, 326.079): '7j-4', (26.222, 306.436): '7j-5', (25.111, 286.793): '7j-6', (25.111, 373.223): '7k-4', (26.222, 353.58): '7k-5', (25.111, 333.937): '7k-6', (25.111, 420.367): '7l-4', (26.222, 400.724): '7l-5', (25.111, 381.081): '7l-6', (25.111, 467.511): '7m-4', (26.222, 447.868): '7m-5', (25.111, 428.225): '7m-6', (25.111, 514.655): '7n-4', (26.222, 495.012): '7n-5', (25.111, 475.369): '7n-6', (25.111, 561.799): '7o-4', (26.222, 542.156): '7o-5', (25.111, 522.513): '7o-6', (25.111, 608.943): '7p-4', (26.222, 589.3): '7p-5', (25.111, 569.657): '7p-6', (25.111, 656.087): '7q-4', (26.222, 636.444): '7q-5', (25.111, 616.801): '7q-6', (25.111, 703.231): '7r-4', (26.222, 683.588): '7r-5', (25.111, 663.945): '7r-6', (25.111, 750.375): '7s-4', (26.222, 730.732): '7s-5', (25.111, 711.089): '7s-6', (25.111, 797.519): '7t-4', (26.222, 777.876): '7t-5', (25.111, 758.233): '7t-6', (25.111, 805.377): '7u-2', (1.111, 3.929): '1a-3', (2.222, 23.572): '1a-2', (1.111, 43.215): '1a-1', (5.111, -19.643): '2a-5', (6.222, 0.0): '2a-4', (5.111, 19.643): '2a-3', (9.111, -43.215): '3a-5', (10.222, -23.572): '3a-4', (9.111, -3.929): '3a-3', (13.111, -66.787): '4a-5', (14.222, -47.144): '4a-4', (13.111, -27.501): '4a-3', (17.111, -90.359): '5a-5', (18.222, -70.716): '5a-4', (17.111, -51.073): '5a-3', (21.111, -113.931): '6a-5', (22.222, -94.288): '6a-4', (21.111, -74.645): '6a-3', (25.111, -137.503): '7a-5', (26.222, -117.86): '7a-4', (25.111, -98.217): '7a-3', (1.111, -3.929): '1-0', (5.111, -27.501): '2-0', (9.111, -51.073): '3-0', (13.111, -74.645): '4-0', (17.111, -98.217): '5-0', (21.111, -121.789): '6-0', (25.111, -145.361): '7-0', (29.111, -168.933): '8-0', (29.778, -165.004): '9-1', (29.778, -117.86): '9-2', (29.778, -70.716): '9-3', (29.778, -23.572): '9-4', (29.778, 23.572): '9-5', (29.778, 70.716): '9-6', (29.778, 117.86): '9-7', (29.778, 165.004): '9-8', (29.778, 212.148): '9-9', (29.778, 259.292): '9-10', (29.778, 306.436): '9-11', (29.778, 353.58): '9-12', (29.778, 400.724): '9-13', (29.778, 447.868): '9-14', (29.778, 495.012): '9-15', (29.778, 542.156): '9-16', (29.778, 589.3): '9-17', (29.778, 636.444): '9-18', (29.778, 683.588): '9-19', (29.778, 730.732): '9-20', (29.778, 777.876): '9-21', (28.0, -141.432): '8a', (25.778, -141.432): '8a-1', (26.889, -121.789): '8a-2', (29.111, -121.789): '8a-3', (29.111, -161.075): '8a-4', (28.0, -94.288): '8b', (26.889, -113.931): '8b-1', (25.778, -94.288): '8b-2', (26.889, -74.645): '8b-3', (29.111, -74.645): '8b-4', (29.111, -113.931): '8b-5', (28.0, -47.144): '8c', (26.889, -66.787): '8c-1', (25.778, -47.144): '8c-2', (26.889, -27.501): '8c-3', (29.111, -27.501): '8c-4', (29.111, -66.787): '8c-5', (28.0, 0.0): '8d', (26.889, -19.643): '8d-1', (25.778, 0.0): '8d-2', (26.889, 19.643): '8d-3', (29.111, 19.643): '8d-4', (29.111, -19.643): '8d-5', (28.0, 47.144): '8e', (26.889, 27.501): '8e-1', (25.778, 47.144): '8e-2', (26.889, 66.787): '8e-3', (29.111, 66.787): '8e-4', (29.111, 27.501): '8e-5', (28.0, 94.288): '8f', (26.889, 74.645): '8f-1', (25.778, 94.288): '8f-2', (26.889, 113.931): '8f-3', (29.111, 113.931): '8f-4', (29.111, 74.645): '8f-5', (28.0, 141.432): '8g', (26.889, 121.789): '8g-1', (25.778, 141.432): '8g-2', (26.889, 161.075): '8g-3', (29.111, 161.075): '8g-4', (29.111, 121.789): '8g-5', (28.0, 188.576): '8h', (26.889, 168.933): '8h-1', (25.778, 188.576): '8h-2', (26.889, 208.219): '8h-3', (29.111, 208.219): '8h-4', (29.111, 168.933): '8h-5', (28.0, 235.72): '8i', (26.889, 216.077): '8i-1', (25.778, 235.72): '8i-2', (26.889, 255.363): '8i-3', (29.111, 255.363): '8i-4', (29.111, 216.077): '8i-5', (28.0, 282.864): '8j', (26.889, 263.221): '8j-1', (25.778, 282.864): '8j-2', (26.889, 302.507): '8j-3', (29.111, 302.507): '8j-4', (29.111, 263.221): '8j-5', (28.0, 330.008): '8k', (26.889, 310.365): '8k-1', (25.778, 330.008): '8k-2', (26.889, 349.651): '8k-3', (29.111, 349.651): '8k-4', (29.111, 310.365): '8k-5', (28.0, 377.152): '8l', (26.889, 357.509): '8l-1', (25.778, 377.152): '8l-2', (26.889, 396.795): '8l-3', (29.111, 396.795): '8l-4', (29.111, 357.509): '8l-5', (28.0, 424.296): '8m', (26.889, 404.653): '8m-1', (25.778, 424.296): '8m-2', (26.889, 443.939): '8m-3', (29.111, 443.939): '8m-4', (29.111, 404.653): '8m-5', (28.0, 471.44): '8n', (26.889, 451.797): '8n-1', (25.778, 471.44): '8n-2', (26.889, 491.083): '8n-3', (29.111, 491.083): '8n-4', (29.111, 451.797): '8n-5', (28.0, 518.584): '8o', (26.889, 498.941): '8o-1', (25.778, 518.584): '8o-2', (26.889, 538.227): '8o-3', (29.111, 538.227): '8o-4', (29.111, 498.941): '8o-5', (28.0, 565.728): '8p', (26.889, 546.085): '8p-1', (25.778, 565.728): '8p-2', (26.889, 585.371): '8p-3', (29.111, 585.371): '8p-4', (29.111, 546.085): '8p-5', (28.0, 612.872): '8q', (26.889, 593.229): '8q-1', (25.778, 612.872): '8q-2', (26.889, 632.515): '8q-3', (29.111, 632.515): '8q-4', (29.111, 593.229): '8q-5', (28.0, 660.016): '8r', (26.889, 640.373): '8r-1', (25.778, 660.016): '8r-2', (26.889, 679.659): '8r-3', (29.111, 679.659): '8r-4', (29.111, 640.373): '8r-5', (28.0, 707.16): '8s', (26.889, 687.517): '8s-1', (25.778, 707.16): '8s-2', (26.889, 726.803): '8s-3', (29.111, 726.803): '8s-4', (29.111, 687.517): '8s-5', (28.0, 754.304): '8t', (26.889, 734.661): '8t-1', (25.778, 754.304): '8t-2', (26.889, 773.947): '8t-3', (29.111, 773.947): '8t-4', (29.111, 734.661): '8t-5', (28.0, 801.448): '8u', (26.889, 781.805): '8u-1', (25.778, 801.448): '8u-2', (29.111, 781.805): '8u-3'}\n",
    "\n",
    "\n",
    "\n",
    "def roman(num):\n",
    "    int_to_roman = [(1000,\"M\"),(900,\"CM\"),(500,\"D\"),(400,\"CD\"),\n",
    "                    (100,\"C\"),(90,\"XC\"),(50,\"L\"),(40,\"XL\"),\n",
    "                    (10,\"X\"),(9,\"IX\"),(5,\"V\"),(4,\"IV\"),(1,\"I\")]\n",
    "    roman_num = \"\"\n",
    "    for number,roman in int_to_roman:\n",
    "\n",
    "        count,num = divmod(num,number)\n",
    "        roman_num += roman * count\n",
    "        if num == 0:\n",
    "            break\n",
    "    return roman_num\n",
    "    \n",
    "    \n",
    "class Area():\n",
    "    def __init__(self,span,lower,upper):\n",
    "        self.span = span\n",
    "        self.lower = lower\n",
    "        self.upper = upper\n",
    "\n",
    "    def combine(self,another_area):\n",
    "\n",
    "        a,b = [self.span,self.lower ,self.upper],[another_area.span,another_area.lower ,another_area.upper]\n",
    "        if a[0][0] > b[0][0]:\n",
    "            a,b = b,a \n",
    "\n",
    "        self.span  =a[0][:-1] + b[0]\n",
    "        self.lower = a[1]+b[1]\n",
    "        self.upper = a[2]+b[2]\n",
    "        return self\n",
    "\n",
    "    def conclude(self,point):\n",
    "        #判断点是不是在area内\n",
    "        x,y = point\n",
    "        if self.span[0] < x <=self.span[-1]:\n",
    "            for index in range(len(self.span)-1):\n",
    "                left,right = self.span[index],self.span[index+1]\n",
    "                upper,lower = self.upper[index],self.lower[index]\n",
    "                ku,bu = upper\n",
    "                kl,bl = lower\n",
    "                if left < x <= right and kl*x+bl < y <= ku*x + bu :\n",
    "                    return True\n",
    "        return False\n",
    "\n",
    "    def centroid(self):\n",
    "        #计算重心\n",
    "        upper_points = [(self.span[0],self.upper[0][0]*self.span[0] + self.upper[0][1])]\n",
    "        lower_points = [(self.span[0],self.lower[0][0]*self.span[0] + self.lower[0][1])]\n",
    "\n",
    "        for index in range(len(self.span)-1):\n",
    "            upper_points.append((self.span[index+1],self.upper[index][0]*self.span[index+1] + self.upper[index][1]))\n",
    "            lower_points.append((self.span[index+1],self.lower[index][0]*self.span[index+1] + self.lower[index][1]))\n",
    "\n",
    "        points = lower_points + [i for i in reversed(upper_points)]\n",
    "\n",
    "        A = 0.0\n",
    "        point_p = points[-1]\n",
    "        for point in points:\n",
    "            A += (point[1]*point_p[0] - point[0]*point_p[1])\n",
    "            point_p = point\n",
    "        A = abs(A)/2\n",
    "\n",
    "        c_x, c_y = 0.0, 0.0\n",
    "        point_p = points[-1] # point_p 表示前一节点\n",
    "        for point in points:\n",
    "            c_x +=((point[0] + point_p[0]) * (point[1]*point_p[0] - point_p[1]*point[0]))\n",
    "            c_y +=((point[1] + point_p[1]) * (point[1]*point_p[0] - point_p[1]*point[0]))\n",
    "            point_p = point\n",
    "\n",
    "        return c_x / (6*A), c_y / (6*A)\n",
    "    def get_apex(self):\n",
    "        ptl = []\n",
    "        ptu = []\n",
    "        for i in range(len(self.lower)):\n",
    "            ptu.append((self.span[i],round(self.upper[i][0]*self.span[i]+self.upper[i][1],3)))\n",
    "            ptl.append((self.span[i],round(self.lower[i][0]*self.span[i]+self.lower[i][1],3)))\n",
    "\n",
    "        ptu.append((self.span[i+1],round(self.upper[i][0]*self.span[i+1]+self.upper[i][1],3)))\n",
    "        ptl.append((self.span[i+1],round(self.lower[i][0]*self.span[i+1]+self.lower[i][1],3)))\n",
    "\n",
    "        return [ptl,ptu]\n",
    "                    \n",
    "Tlist = []\n",
    "Elist = []\n",
    "plot_listx = []\n",
    "plot_listy = []\n",
    "\n",
    "#找正三角形中心点\n",
    "for x in range(30):\n",
    "    for i in range(-10,20):\n",
    "        xlim = x\n",
    "        if xlim%8 == 1 :\n",
    "            xlim = x  + 1/3\n",
    "            ylim  = 5.893 * 8 * i\n",
    "        elif xlim%8 == 3:\n",
    "            xlim = x -1/3\n",
    "            ylim  = 5.893 * 8 * i + 5.893 * 4 \n",
    "        elif xlim%8 == 5:\n",
    "            xlim = x + 1/3\n",
    "            ylim  = 5.893 * 8 * i + 5.893 * 4\n",
    "        elif xlim%8 == 7 :\n",
    "            xlim = x -1/3\n",
    "            ylim  = 5.893 * 8 * i\n",
    "        else:\n",
    "            continue\n",
    "        plot_listx.append(xlim)\n",
    "        plot_listy.append(ylim)    \n",
    "\n",
    "c = set([(plot_listx[i],plot_listy[i]) for i in range(len(plot_listx))])\n",
    "\n",
    "for st in [-2,2,6,10,14,18,22,26]:\n",
    "    e = [i for i in c if i[1] >= -5.893*i[0] and st<i[0]<st+4 and i[1]<802]\n",
    "    e.sort(key = lambda x:(x[1],x[0]))\n",
    "    smallx,bigx = st + 2/3,st+4-2/3\n",
    "    \n",
    "    for i in e :\n",
    "        x,y = i\n",
    "        if 1 != 0:\n",
    "            if round(x,5) == round(smallx,5):\n",
    "                area1 = Area([st,x],[[3*5.893,y-3*5.893*x]],[[-3*5.893,y+3*5.893*x]]) #E1\n",
    "                area2 = Area([st,x],[[5.893,y-(st+2)*5.893]],[[3*5.893,y-3*5.893*x]]) #E2\n",
    "                area3 = Area([x,st+2],[[5.893,y-(st+2)*5.893]],[[0,y]]) #E2\n",
    "                area4 = Area([st,x],[[-3*5.893,y+3*5.893*x]],[[-5.893,y+(st+2)*5.893]]) #E3\n",
    "                area5 = Area([x,st+2],[[0,y]],[[-5.893,y+(st+2)*5.893]]) #E3\n",
    "\n",
    "                E1,E2,E3 = area1,area2.combine(area3),area4.combine(area5)\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    "            elif round(x,5) == round(bigx,5): \n",
    "                area1 = Area([st+2,x],[[-5.893,y+(st+2)*5.893]],[[0,y]]) #E1\n",
    "                area2 = Area([x,st+4],[[-5.893,y+(st+2)*5.893]],[[-3*5.893,y+3*5.893*x]]) #E1\n",
    "                area3 = Area([x,st+4],[[-3*5.893,y+3*5.893*x]],[[3*5.893,y-3*5.893*x]]) #E2\n",
    "                area4 = Area([st+2,x],[[0,y]],[[5.893,y+(st+2)*-5.893]]) #E3\n",
    "                area5 = Area([x,st+4],[[3*5.893,y-3*5.893*x]],[[5.893,y+(st+2)*-5.893]]) #E3  \n",
    "                E1,E2,E3 = area1.combine(area2),area3,area4.combine(area5)\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    " \n",
    "    \n",
    "    y = (st+2) * -5.893\n",
    "    while y < 802:\n",
    "            area = Area([st,st+2,st+4],[[-5.893,y+(st+2)*5.893],[5.893,y-(st+2)*5.893]],[[5.893,y-(st-6)*5.893],[-5.893,y+(st+10)*5.893]])\n",
    "            Tlist.append(area)\n",
    "            y += 8*5.893\n",
    "            \n",
    "            \n",
    "def 获得亚群系(point):\n",
    "    x,y = point\n",
    "    if y>  4*5.893*1.8099* x: a = 0\n",
    "    elif y>  2*5.893*1.8099* x: a = 1\n",
    "    elif y >  5.893*1.8099* x: a = 2\n",
    "    elif y >  (1.0/3)*5.893*1.8099* x : a = 3    \n",
    "    elif y >= 0: a = 4\n",
    "    elif y >  -(1.0/3)*5.893*1.8099* x : a = 5\n",
    "    elif y >=  -0.5*5.893*1.8099* x: a = 6\n",
    "    elif y >  -(3.0/5)*5.893*1.8099* x : a = 7  \n",
    "    elif y >  -(2.0/3)*5.893*1.8099* x : a = 8  \n",
    "    elif y >=  -5.893*1.8099* x: a = 9\n",
    "    else : a = 10\n",
    "        \n",
    "    if x <2: b = \"P\"\n",
    "    elif x<6: b = \"B\"\n",
    "    elif x<10: b = \"CT\"\n",
    "    elif x<14: b = \"WT\"\n",
    "    elif x<22: b = \"ST\"\n",
    "    elif x<30: b = \"T\"\n",
    "    else :b = \"ERROR\"\n",
    "        \n",
    "    return b + \"-\" + str(a+1)\n",
    "\n",
    "def 获得亚群系相关的四列数据(counter):\n",
    "    keys = list(counter.keys())\n",
    "    def goal(x):\n",
    "        temperate = x.split(\"-\")[0]\n",
    "        num = x.split(\"-\")[1]\n",
    "        return \"P,B,CT,WT,ST,T,ERROR\".index(temperate) * 100 + int(num)\n",
    "    keys.sort(key = lambda x : goal(x))\n",
    "    亚群系名 = \",\".join(i for i in keys)\n",
    "     \n",
    "    maxinum = 0\n",
    "    secondnum = 0\n",
    "    total = 0\n",
    "    主导区 = \"\"\n",
    "    第二主导区 = \"\"\n",
    "    for i in keys:\n",
    "        total += counter[i]\n",
    "        if counter[i] > maxinum:\n",
    "            secondnum = maxinum\n",
    "            maxinum = counter[i]\n",
    "            第二主导区 = 主导区\n",
    "            主导区 = i\n",
    "    \n",
    "    主导区占比 = counter[主导区]/total\n",
    "    if 第二主导区:\n",
    "        第二主导区占比 = counter[第二主导区]/total\n",
    "    else: \n",
    "        第二主导区占比 = 0\n",
    "    statu = \"\"\n",
    "    if 主导区占比 > 0.6379:\n",
    "        statu = \"稳态\"\n",
    "    elif 主导区占比 > 0.3721 and 第二主导区占比 > 0.3721:\n",
    "        statu = \"双亚稳态\"\n",
    "    elif 主导区占比 > 0.3721:\n",
    "        statu = \"单亚稳态\"\n",
    "    else:\n",
    "        statu = \"混沌态\"\n",
    "    if statu ==\"双亚稳态\":\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%,\"+ str(round(第二主导区占比*100,2)) +\"%\"\n",
    "        亚群系名 = 主导区+\",\"+第二主导区\n",
    "    elif statu == \"稳态\" :\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%\"\n",
    "        亚群系名 = 主导区\n",
    "    else:\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%\"\n",
    "    \n",
    "    \n",
    "    return 亚群系名,主导区,主导区占比,statu\n",
    "\n",
    "def 获得六边形分区(point):\n",
    "    tb,e = point[0],point[1]/1.8099\n",
    "    for area in Elist + Tlist:\n",
    "        if area.conclude((tb,e)):\n",
    "            x,y = area.centroid()\n",
    "            return sign[(round(x,3),round(y,3))]\n",
    "    return \"Error\"\n",
    "\n",
    "\n",
    "def 获得六边形图相关的四列数据(counter):\n",
    "    keys = list(counter.keys())\n",
    "    keys.sort()\n",
    "    \n",
    "    六边形分区 = \",\".join(i for i in keys)\n",
    "    \n",
    "    maxinum = 0\n",
    "    secondnum = 0\n",
    "    total = 0\n",
    "    主导区 = \"\"\n",
    "    第二主导区 = \"\"\n",
    "    for i in keys:\n",
    "        total += counter[i]\n",
    "        if counter[i] > maxinum:\n",
    "            secondnum = maxinum\n",
    "            maxinum = counter[i]\n",
    "            第二主导区 = 主导区\n",
    "            主导区 = i\n",
    "    \n",
    "    主导区占比 = counter[主导区]/total\n",
    "    if 第二主导区:\n",
    "        第二主导区占比 = counter[第二主导区]/total\n",
    "    else: \n",
    "        第二主导区占比 = 0\n",
    "    statu = \"\"\n",
    "    if 主导区占比 > 0.6379:\n",
    "        statu = \"稳态\"\n",
    "    elif 主导区占比 > 0.3721 and 第二主导区占比 > 0.3721:\n",
    "        statu = \"双亚稳态\"\n",
    "    elif 主导区占比 > 0.3721:\n",
    "        statu = \"单亚稳态\"\n",
    "    else:\n",
    "        statu = \"混沌态\"\n",
    "    if statu ==\"双亚稳态\":\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%,\"+ str(round(第二主导区占比*100,2)) +\"%\"\n",
    "        六边形分区 = 主导区+\",\"+第二主导区\n",
    "    elif statu == \"稳态\" :\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%\"\n",
    "        六边形分区 = 主导区\n",
    "    else:\n",
    "        主导区占比 = str(round(主导区占比*100,2))+\"%\"\n",
    "    return 六边形分区,主导区,主导区占比,statu\n",
    "\n",
    "def 获得大小区分区(points):\n",
    "    counter = {}\n",
    "    counter2 = {}\n",
    "    for point in points:\n",
    "        大区列表 = []\n",
    "        小区列表 = []\n",
    "        x,y = float(point[0]),float(point[1])\n",
    "        for i in big:\n",
    "            if float(big[i][0])<=x<float(big[i][2]) and float(big[i][1])<=y<float(big[i][3]):\n",
    "                大区列表.append(i)\n",
    "        for i in small:\n",
    "            if float(small[i][0])<=x<float(small[i][2]) and float(small[i][1])<=y<float(small[i][3]):\n",
    "                小区列表.append(i)\n",
    "        \n",
    "        for i in 大区列表:    \n",
    "            \n",
    "            sign = False\n",
    "            for area in 大区[i]:\n",
    "                path = mpltPath.Path(area)\n",
    "                if path.contains_point(point):\n",
    "                    sign = True\n",
    "                    break\n",
    "            if sign:\n",
    "                if i not in counter:\n",
    "                    counter[i] = 1\n",
    "                else:\n",
    "                    counter[i] += 1\n",
    "                break\n",
    "        for i in 小区列表:    \n",
    "            sign = False\n",
    "            for area in 小区[i]:\n",
    "                path = mpltPath.Path(area)\n",
    "                if path.contains_point(point):\n",
    "                    sign = True\n",
    "                    break\n",
    "            if sign:\n",
    "                if i not in counter2:\n",
    "                    counter2[i] = 1\n",
    "                else:\n",
    "                    counter2[i] += 1\n",
    "                break      \n",
    "                \n",
    "    max1,max2 = 0,0\n",
    "    c1,c2 = \"\",\"\"\n",
    "    \n",
    "    for i in counter:\n",
    "        if counter[i] > max1:\n",
    "            max1 = counter[i]\n",
    "            c1 = i\n",
    "    for i in counter2:\n",
    "        if counter2[i] > max2:\n",
    "            max2 = counter2[i]\n",
    "            c2 = i\n",
    "    return c1,c2\n",
    "\n",
    "def set_cell_border(cell, **kwargs):\n",
    "    \"\"\"\n",
    "    Set cell`s border\n",
    "    Usage:\n",
    "    set_cell_border(\n",
    "        cell,\n",
    "        top={\"sz\": 12, \"val\": \"single\", \"color\": \"#FF0000\", \"space\": \"0\"},\n",
    "        bottom={\"sz\": 12, \"color\": \"#00FF00\", \"val\": \"single\"},\n",
    "        left={\"sz\": 24, \"val\": \"dashed\", \"shadow\": \"true\"},\n",
    "        right={\"sz\": 12, \"val\": \"dashed\"},\n",
    "    )\n",
    "    \"\"\"\n",
    "    tc = cell._tc\n",
    "    tcPr = tc.get_or_add_tcPr()\n",
    "\n",
    "    # check for tag existnace, if none found, then create one\n",
    "    tcBorders = tcPr.first_child_found_in(\"w:tcBorders\")\n",
    "    if tcBorders is None:\n",
    "        tcBorders = OxmlElement('w:tcBorders')\n",
    "        tcPr.append(tcBorders)\n",
    "\n",
    "    # list over all available tags\n",
    "    for edge in ('left', 'top', 'right', 'bottom', 'insideH', 'insideV'):\n",
    "        edge_data = kwargs.get(edge)\n",
    "        if edge_data:\n",
    "            tag = 'w:{}'.format(edge)\n",
    "\n",
    "            # check for tag existnace, if none found, then create one\n",
    "            element = tcBorders.find(qn(tag))\n",
    "            if element is None:\n",
    "                element = OxmlElement(tag)\n",
    "                tcBorders.append(element)\n",
    "\n",
    "            # looks like order of attributes is important\n",
    "            for key in [\"sz\", \"val\", \"color\", \"space\", \"shadow\"]:\n",
    "                if key in edge_data:\n",
    "                    element.set(qn('w:{}'.format(key)), str(edge_data[key]))\n",
    "                    \n",
    "def add(document,addtype,content,addto = None ,charsize = 1,picsize = (1,1),style = None,mid = False,bold = False,indent = 0):\n",
    "    if addto:\n",
    "        paragraph = addto\n",
    "    else:\n",
    "        paragraph = document.add_paragraph() # 添加新段落\n",
    "    \"\"\"if addtype == \"head\":\n",
    "        run = document.add_heading(content, headlevel)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\"\"\"\n",
    "    if addtype == \"char\":\n",
    "        run = paragraph.add_run(content,style=style)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "        if indent:\n",
    "            paragraph.paragraph_format.first_line_indent = Inches(indent)\n",
    "    elif addtype == \"pic\":\n",
    "        if picsize:\n",
    "            paragraph.add_run().add_picture(content, width=Cm(picsize[0]),height = Cm(picsize[1]))\n",
    "        else:\n",
    "            paragraph.add_run().add_picture(content)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "    return paragraph\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0d359e5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#1读取类型csv\n",
    "typelist = []\n",
    "for root,dirs,files in os.walk(csv_path,topdown=False): \n",
    "    for file in files:\n",
    "        if file.endswith(\".csv\"):\n",
    "            filename_path=os.path.join(root,file)\n",
    "            typelist.append(filename_path)\n",
    "\"\"\"typelist = []\n",
    "for i in filelist:\n",
    "    if \"类型csv\" in i and i.endswith(\".csv\") :\n",
    "        typelist.append(i)\n",
    "typelist = list(set(typelist))\n",
    "try:\n",
    "    typelist.sort(key = lambda x:int(x.split(\"\\\\\")[-1].split(\".\")[3]))\n",
    "except:\n",
    "    typelist.sort(key = lambda x:int(x[:-4].split(\"\\\\\")[-1].split(\"-\")[2]))\n",
    "    \"\"\"\n",
    "\n",
    "total_data = {} \n",
    "#类型csv - 各项数据\n",
    "f=open(\"大区.txt\", 'r')\n",
    "大区 = eval(f.read())\n",
    "f=open(\"小区.txt\", 'r')\n",
    "小区 = eval(f.read())\n",
    "f=open(\"大小区外接矩形.txt\")\n",
    "exec(f.read())\n",
    "for i in typelist:\n",
    "    #print(i)\n",
    "    key = i.split(\"\\\\\")[-1]\n",
    "    total_data[key] = {}\n",
    "    df = pd.read_csv(i,engine = \"python\")\n",
    "    pointlist = [(df[\"tb\"][ii],df[\"E_sum\"][ii]) for ii in range(len(df))]\n",
    "    \n",
    "    #2 计算亚群系相关数据：表里的第一第二、倒数第一第二列\n",
    "    counter = {}\n",
    "    for point in pointlist:    \n",
    "        area = 获得亚群系(point)\n",
    "        if area in counter:\n",
    "            counter[area] += 1\n",
    "        else:\n",
    "            counter[area] = 1\n",
    "            \n",
    "    亚群系名,主导区,主导区占比,statu = 获得亚群系相关的四列数据(counter)\n",
    "    total_data[key][\"亚群系相关\"] = {\n",
    "        \"亚群系\": 亚群系名,\n",
    "        \"主导区\": 主导区,\n",
    "        \"群丛状态\": statu ,\n",
    "        \"主导区占比\": 主导区占比\n",
    "    }\n",
    "    \n",
    "    #3 群丛组、亚群丛组\n",
    "    xy = [(df[\"XX\"][ii],df[\"YY\"][ii]) for ii in range(len(df))]\n",
    "    c1,c2 = 获得大小区分区(xy)\n",
    "    total_data[key][\"植被区相关\"] = {\n",
    "        \"大区\": c1,\n",
    "        \"小区\": c2,\n",
    "    }\n",
    "    #4 六边形图\n",
    "    counter = {}\n",
    "    for point in pointlist:    \n",
    "        area = 获得六边形分区(point)\n",
    "        if area in counter:\n",
    "            counter[area] += 1\n",
    "        else:\n",
    "            counter[area] = 1\n",
    "    六边形分区,主导区,主导区占比,statu = 获得六边形图相关的四列数据(counter)\n",
    "    total_data[key][\"六边形图相关\"] = {\n",
    "        \"六边形分区\": 六边形分区,\n",
    "        \"主导区\": 主导区,\n",
    "        \"群丛状态\": statu ,\n",
    "        \"主导区占比\": 主导区占比\n",
    "    }\n",
    "    \n",
    "l = []\n",
    "for i in total_data:\n",
    "    l.append([total_data[i][\"亚群系相关\"][\"亚群系\"],total_data[i][\"亚群系相关\"][\"主导区\"],total_data[i][\"植被区相关\"][\"大区\"],total_data[i][\"植被区相关\"][\"小区\"],i[:-4],total_data[i][\"亚群系相关\"][\"群丛状态\"],total_data[i][\"亚群系相关\"][\"主导区占比\"]])\n",
    "    \n",
    "def grade(key):\n",
    "    mark = 0\n",
    "    if \",\" in key: mark += 99999999\n",
    "    \n",
    "    def getcode(一节):\n",
    "        for i in \"P,B,CT,WT,ST,T,ERROR\".split(\",\"):\n",
    "            if 一节.startswith(i):\n",
    "                return 10**\"P,B,CT,WT,ST,T,ERROR\".split(\",\").index(i) + int(一节.split(\"-\")[-1])\n",
    "                break\n",
    "    return [int(\",\" in key)]+[getcode(i) for i in key.split(\",\")] \n",
    "l.sort(key = lambda x : [[\"稳态\",\"单亚稳态\",\"双亚稳态\",\"混沌态\"].index(x[-2])]+grade(x[0])+grade(x[1]) + [int(x[2]),int(x[3]),-float(x[6].split(\",\")[0][:-1])])    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a23a42e1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "a7bee058",
   "metadata": {},
   "source": [
    "# 比值分区"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "83782a1f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第1列合并: [(0, 15), (15, 18), (18, 55), (55, 57), (57, 58), (58, 59), (59, 64), (64, 72), (72, 75), (75, 87), (87, 91), (91, 92), (92, 93), (93, 94), (94, 95), (95, 98), (98, 99), (99, 100), (100, 102), (102, 105), (105, 110), (110, 113), (113, 115)]\n",
      "第2列合并: [(0, 15), (15, 18), (18, 55), (55, 57), (57, 58), (58, 59), (59, 61), (61, 64), (64, 65), (65, 71), (71, 72), (72, 73), (73, 74), (74, 75), (75, 79), (79, 85), (85, 87), (87, 91), (91, 92), (92, 93), (93, 94), (94, 95), (95, 97), (97, 98), (98, 99), (99, 100), (100, 102), (102, 105), (105, 110), (110, 113), (113, 114), (114, 115)]\n",
      "第3列合并: [(0, 1), (1, 7), (7, 14), (14, 15), (15, 18), (18, 19), (19, 21), (21, 26), (26, 31), (31, 37), (37, 55), (55, 57), (57, 58), (58, 59), (59, 60), (60, 61), (61, 63), (63, 64), (64, 65), (65, 69), (69, 70), (70, 71), (71, 72), (72, 73), (73, 74), (74, 75), (75, 77), (77, 78), (78, 79), (79, 83), (83, 85), (85, 86), (86, 87), (87, 91), (91, 92), (92, 93), (93, 94), (94, 95), (95, 97), (97, 98), (98, 99), (99, 100), (100, 101), (101, 102), (102, 103), (103, 105), (105, 106), (106, 107), (107, 110), (110, 111), (111, 113), (113, 114), (114, 115)]\n",
      "第4列合并: [(0, 1), (1, 7), (7, 8), (8, 14), (14, 15), (15, 18), (18, 19), (19, 21), (21, 23), (23, 26), (26, 28), (28, 31), (31, 37), (37, 49), (49, 55), (55, 56), (56, 57), (57, 58), (58, 59), (59, 60), (60, 61), (61, 63), (63, 64), (64, 65), (65, 69), (69, 70), (70, 71), (71, 72), (72, 73), (73, 74), (74, 75), (75, 76), (76, 77), (77, 78), (78, 79), (79, 83), (83, 85), (85, 86), (86, 87), (87, 90), (90, 91), (91, 92), (92, 93), (93, 94), (94, 95), (95, 97), (97, 98), (98, 99), (99, 100), (100, 101), (101, 102), (102, 103), (103, 105), (105, 106), (106, 107), (107, 110), (110, 111), (111, 113), (113, 114), (114, 115)]\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "object of type 'int' has no len()",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_21320\\4262075399.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m    141\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    142\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 143\u001b[1;33m \u001b[0mtext\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf\"{name}共{len(l)}个群丛，在比值分区体系中有{稳态数量}的群丛呈稳态分布、{单亚稳态数量}的群丛呈单亚稳态分布、{双亚稳态数量}的群丛呈双亚稳态分布、{混沌态数量}的群丛呈混沌态分布，划分为{len(kk)}个亚群系、{len(span2)}个群丛组、{len(span3)}个亚群丛组\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    144\u001b[0m \u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdocument\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"char\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0maddto\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mp1\u001b[0m \u001b[1;33m,\u001b[0m\u001b[0mcharsize\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m12\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mstyle\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"宋\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mindent\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    145\u001b[0m \u001b[0mdocument\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'比值分区表.docx'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# 存储WORD文档\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: object of type 'int' has no len()"
     ]
    }
   ],
   "source": [
    "from docx import Document\n",
    "from docx.shared import Cm, Pt\n",
    "from docx.document import Document as Doc\n",
    "from docx.oxml.ns import qn\n",
    "from docx.enum.style import WD_STYLE_TYPE\n",
    "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT,WD_ALIGN_PARAGRAPH\n",
    "from docx.enum.table import WD_TABLE_ALIGNMENT,WD_CELL_VERTICAL_ALIGNMENT\n",
    "from docx.shared import Inches\n",
    "from docx.oxml import OxmlElement\n",
    "import re\n",
    "from PIL import Image\n",
    "\n",
    "document = Document()\n",
    "\n",
    "style_song = document.styles.add_style('宋', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '宋体'\n",
    "document.styles['宋']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')\n",
    "\n",
    "style_song = document.styles.add_style('黑', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '黑体'\n",
    "document.styles['黑']._element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')\n",
    "\n",
    "style_song = document.styles.add_style('新罗马', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = 'Times new Roman'\n",
    "document.styles['新罗马']._element.rPr.rFonts.set(qn('w:eastAsia'), u'Times new Roman')\n",
    "\n",
    "piccode = 1\n",
    "tablecode = 1\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "text = \"\"\n",
    "p1 = add(document,\"char\",text ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "                    \n",
    "Fields=\"亚群系\t主导区\t群丛组\t亚群丛组\t群丛\t群丛状态\t主导区占比\".split(\"\\t\")\n",
    "table = document.add_table(rows=1, cols=7,style=None)\n",
    "table.alignment=WD_TABLE_ALIGNMENT.CENTER\n",
    "\n",
    "#写标题行，并设置字体\n",
    "\n",
    "hdr_cells = table.rows[0].cells\n",
    "for aa in range(7):\n",
    "    set_cell_border(\n",
    "    hdr_cells[aa],\n",
    "    top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "    bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "    left = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "    right = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"})\n",
    "\n",
    "for i in range(7):\n",
    "    hdr_cells[i].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "    run=hdr_cells[i].paragraphs[0].add_run(Fields[i],style = '宋')\n",
    "    run.font.size = Pt(10.5)\n",
    "    run.font.bold=True\n",
    "\n",
    "\n",
    "for i in range(len(l)):\n",
    "    ld = l[i]\n",
    "    row_cells = table.add_row().cells\n",
    "    for g in range(7):\n",
    "        set_cell_border(\n",
    "        row_cells[g],\n",
    "        top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "        bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "        left = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "        right = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"})\n",
    "        row_cells[g].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "        run=row_cells[g].paragraphs[0].add_run(str(ld[g]),style = \"新罗马\")\n",
    "        run.font.size = Pt(10.5)\n",
    "\n",
    "table.cell(0,0).width = Cm(2)\n",
    "table.cell(0,1).width = Cm(1.5)\n",
    "table.cell(0,2).width = Cm(1.5)\n",
    "for i in range(3,5):\n",
    "    table.cell(0,i).width = Cm(1.7)\n",
    "for i in range(5,7):\n",
    "    table.cell(0,i).width = Cm(1.96)\n",
    "\n",
    "#合并单元格\n",
    "def 迭代合并(table,spans,layer):\n",
    "    cy = [i[layer] for i in l]\n",
    "    span2 = []\n",
    "    for i in spans:\n",
    "        if i[1]-i[0] == 1:\n",
    "            span2.append(i)\n",
    "            continue\n",
    "        a,b = i[0],i[0]\n",
    "        while a < i[1]:\n",
    "            if cy[a] == cy[b]:\n",
    "                b += 1\n",
    "                if b == i[1]:\n",
    "                    table.rows[a+1].cells[layer].merge(table.rows[b].cells[layer])\n",
    "                    span2.append((a,b))\n",
    "                    \n",
    "                    break\n",
    "            else:  \n",
    "                table.rows[a+1].cells[layer].merge(table.rows[b].cells[layer])\n",
    "                span2.append((a,b))\n",
    "                a = b\n",
    "    print(f\"第{layer+1}列合并:\",span2)            \n",
    "    return span2\n",
    "\n",
    "span = 迭代合并(table,[(0,len(l)-1)],0)\n",
    "kk = len(span)\n",
    "span2,span3 = 0,0\n",
    "for i in [1,2,3]:\n",
    "    span = 迭代合并(table,span,i)\n",
    "    if i == 2: span2 = span\n",
    "    if i == 3: span3 = span\n",
    "        \n",
    "for i in range(len(table.rows)):\n",
    "    for j in (0,1,2,3):\n",
    "        table.rows[i].cells[j].text = table.rows[i].cells[j].text.split(\"\\n\")[0]\n",
    "        table.rows[i].cells[j].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER\n",
    "\n",
    "        \n",
    "count = 1\n",
    "for i in span2:\n",
    "    table.rows[i[0]+1].cells[2].text = roman(count)\n",
    "    count += 1\n",
    "\n",
    "lst = \"ZERO\"\n",
    "count = 0\n",
    "for i in span3:\n",
    "    now =  table.rows[i[0]+1].cells[2].text\n",
    "    if now != lst:\n",
    "        lst = now\n",
    "        count = 0\n",
    "    if now == lst:\n",
    "        count += 1\n",
    "    table.rows[i[0]+1].cells[3].text = table.rows[i[0]+1].cells[2].text + \"-\" + str(count)   \n",
    "    \n",
    "    \n",
    "稳态数量 = str(round ( len([i for i in l if i[-2] == \"稳态\"])  * 100 / len(l),2)) + \"%\"\n",
    "单亚稳态数量 = str(round ( len([i for i in l if i[-2] == \"单亚稳态\"]) * 100 / len(l),2)) + \"%\"\n",
    "双亚稳态数量 =str( round ( len([i for i in l if i[-2] == \"双亚稳态\"]) * 100 / len(l),2)) + \"%\"\n",
    "混沌态数量 = str(round ( len([i for i in l if i[-2] == \"混沌态\"]) * 100 / len(l),2)) + \"%\"\n",
    "\n",
    "\n",
    "\n",
    "text = f\"{name}共{len(l)}个群丛，在比值分区体系中有{稳态数量}的群丛呈稳态分布、{单亚稳态数量}的群丛呈单亚稳态分布、{双亚稳态数量}的群丛呈双亚稳态分布、{混沌态数量}的群丛呈混沌态分布，划分为{kk}个亚群系、{len(span2)}个群丛组、{len(span3)}个亚群丛组\"\n",
    "add(document,\"char\",text,addto = p1 ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "document.save('比值分区表.docx') # 存储WORD文档\n",
    "print(\"end\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d51c6b74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "end\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "fce6e4c4",
   "metadata": {},
   "source": [
    "# 六边形图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f5943037",
   "metadata": {},
   "outputs": [],
   "source": [
    "l = []\n",
    "for i in total_data:\n",
    "    l.append([total_data[i][\"六边形图相关\"][\"六边形分区\"],total_data[i][\"六边形图相关\"][\"主导区\"],total_data[i][\"植被区相关\"][\"大区\"],total_data[i][\"植被区相关\"][\"小区\"],i[:-4],total_data[i][\"六边形图相关\"][\"群丛状态\"],total_data[i][\"六边形图相关\"][\"主导区占比\"]])\n",
    "    \n",
    "\n",
    "l.sort(key = lambda x :[[\"稳态\",\"单亚稳态\",\"双亚稳态\",\"混沌态\"].index(x[-2])] + [int(\",\" in x[0]),x[0].split(\",\"),x[1],x[2],x[3],-float(x[6].split(\",\")[0][:-1])])   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "f0bd134c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from docx import Document\n",
    "from docx.shared import Cm, Pt\n",
    "from docx.document import Document as Doc\n",
    "from docx.oxml.ns import qn\n",
    "from docx.enum.style import WD_STYLE_TYPE\n",
    "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT,WD_ALIGN_PARAGRAPH\n",
    "from docx.enum.table import WD_TABLE_ALIGNMENT,WD_CELL_VERTICAL_ALIGNMENT\n",
    "from docx.shared import Inches\n",
    "from docx.oxml import OxmlElement\n",
    "import re\n",
    "from PIL import Image\n",
    "\n",
    "document = Document()\n",
    "\n",
    "style_song = document.styles.add_style('宋', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '宋体'\n",
    "document.styles['宋']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')\n",
    "\n",
    "style_song = document.styles.add_style('黑', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '黑体'\n",
    "document.styles['黑']._element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')\n",
    "\n",
    "style_song = document.styles.add_style('新罗马', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = 'Times new Roman'\n",
    "document.styles['新罗马']._element.rPr.rFonts.set(qn('w:eastAsia'), u'Times new Roman')\n",
    "\n",
    "piccode = 1\n",
    "tablecode = 1\n",
    "\n",
    "\n",
    "text = \"\"\n",
    "p1 = add(document,\"char\",text ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "         \n",
    "                    \n",
    "Fields=\"亚群系\t主导区\t群丛组\t亚群丛组\t群丛\t群丛状态\t主导区占比\".split(\"\\t\")\n",
    "table = document.add_table(rows=1, cols=7,style=None)\n",
    "table.alignment=WD_TABLE_ALIGNMENT.CENTER\n",
    "\n",
    "#写标题行，并设置字体\n",
    "\n",
    "hdr_cells = table.rows[0].cells\n",
    "for aa in range(7):\n",
    "    set_cell_border(\n",
    "    hdr_cells[aa],\n",
    "    top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "    bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "    left = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "    right = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"})\n",
    "\n",
    "for i in range(7):\n",
    "    hdr_cells[i].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "    run=hdr_cells[i].paragraphs[0].add_run(Fields[i],style = '宋')\n",
    "    run.font.size = Pt(10.5)\n",
    "    run.font.bold=True\n",
    "\n",
    "\n",
    "for i in range(len(l)):\n",
    "    ld = l[i]\n",
    "    row_cells = table.add_row().cells\n",
    "    for g in range(7):\n",
    "        set_cell_border(\n",
    "        row_cells[g],\n",
    "        top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "        bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "        left = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},\n",
    "        right = {\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"})\n",
    "        row_cells[g].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "        run=row_cells[g].paragraphs[0].add_run(str(ld[g]),style = \"新罗马\")\n",
    "        run.font.size = Pt(10.5)\n",
    "\n",
    "table.cell(0,0).width = Cm(2)\n",
    "table.cell(0,1).width = Cm(1.5)\n",
    "table.cell(0,2).width = Cm(1.5)\n",
    "for i in range(3,5):\n",
    "    table.cell(0,i).width = Cm(1.7)\n",
    "for i in range(5,7):\n",
    "    table.cell(0,i).width = Cm(1.96)\n",
    "\n",
    "#合并单元格\n",
    "def 迭代合并(table,spans,layer):\n",
    "    cy = [i[layer] for i in l]\n",
    "    span2 = []\n",
    "    for i in spans:\n",
    "        if i[1]-i[0] == 1:\n",
    "            span2.append(i)\n",
    "            continue\n",
    "        a,b = i[0],i[0]\n",
    "        while a < i[1]:\n",
    "            if cy[a] == cy[b]:\n",
    "                b += 1\n",
    "                if b == i[1]:\n",
    "                    table.rows[a+1].cells[layer].merge(table.rows[b].cells[layer])\n",
    "                    span2.append((a,b))\n",
    "                    \n",
    "                    break\n",
    "            else:  \n",
    "                table.rows[a+1].cells[layer].merge(table.rows[b].cells[layer])\n",
    "                span2.append((a,b))\n",
    "                a = b\n",
    "    print(f\"第{layer+1}列合并:\",span2)            \n",
    "    return span2\n",
    "\n",
    "span = 迭代合并(table,[(0,len(l)-1)],0)\n",
    "kk = len(span)     \n",
    "\n",
    "span2,span3 = 0,0\n",
    "for i in [1,2,3]:\n",
    "    span = 迭代合并(table,span,i)\n",
    "    if i == 2: span2 = span\n",
    "    if i == 3: span3 = span\n",
    "   \n",
    "for i in range(len(table.rows)):\n",
    "    for j in (0,1,2,3):\n",
    "        table.rows[i].cells[j].text = table.rows[i].cells[j].text.split(\"\\n\")[0]\n",
    "        table.rows[i].cells[j].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER\n",
    "\n",
    "        \n",
    "count = 1\n",
    "for i in span2:\n",
    "    table.rows[i[0]+1].cells[2].text = roman(count)\n",
    "    count += 1\n",
    "\n",
    "lst = \"ZERO\"\n",
    "count = 0\n",
    "for i in span3:\n",
    "    now =  table.rows[i[0]+1].cells[2].text\n",
    "    if now != lst:\n",
    "        lst = now\n",
    "        count = 0\n",
    "    if now == lst:\n",
    "        count += 1\n",
    "    table.rows[i[0]+1].cells[3].text = table.rows[i[0]+1].cells[2].text + \"-\" + str(count)   \n",
    "    \n",
    "稳态数量 = str(round ( len([i for i in l if i[-2] == \"稳态\"])  * 100 / len(l),2)) + \"%\"\n",
    "单亚稳态数量 = str(round ( len([i for i in l if i[-2] == \"单亚稳态\"]) * 100 / len(l),2)) + \"%\"\n",
    "双亚稳态数量 =str( round ( len([i for i in l if i[-2] == \"双亚稳态\"]) * 100 / len(l),2)) + \"%\"\n",
    "混沌态数量 = str(round ( len([i for i in l if i[-2] == \"混沌态\"]) * 100 / len(l),2)) + \"%\"\n",
    "\n",
    "\n",
    "\n",
    "text = f\"{name}共{len(l)}个群丛，在六边形分区体系中有{稳态数量}的群丛呈稳态分布、{单亚稳态数量}的群丛呈单亚稳态分布、{双亚稳态数量}的群丛呈双亚稳态分布、{混沌态数量}的群丛呈混沌态分布，划分为{kk}个亚群系、{len(span2)}个群丛组、{len(span3)}个亚群丛组\"\n",
    "add(document,\"char\",text,addto = p1 ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "\n",
    "\n",
    "document.save('六边形图.docx') # 存储WORD文档\n",
    "print(\"1\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e13f68bb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a72ac1e0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec2efe22",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2e076da",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
